package com.example.hotel_lxy.ui.main;


import android.util.Log;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;
import androidx.appcompat.widget.Toolbar;
import com.alibaba.android.arouter.facade.annotation.Autowired;
import com.alibaba.android.arouter.facade.annotation.Route;
import com.alibaba.android.arouter.launcher.ARouter;
import com.example.hotel_lxy.R;
import com.example.hotel_lxy.application.ARouterPath;
import com.example.hotel_lxy.bean.EventBusBean;
import com.example.hotel_lxy.view.calendar.MNCalendarVertical;
import com.example.hotel_lxy.view.calendar.MNCalendarVerticalConfig;
import com.example.hotel_lxy.view.calendar.OnCalendarRangeChooseListener;
import com.ysxsoft.common_base.base.BaseActivity;

import org.greenrobot.eventbus.EventBus;

import java.text.SimpleDateFormat;
import java.util.Date;
import butterknife.BindView;


/**
 * @author Administrator
 */
@Route(path = "/main/CalendarActivity")
public class CalendarActivity extends BaseActivity {


    @BindView(R.id.back)
    ImageView back;
    @BindView(R.id.title)
    TextView title;
    @BindView(R.id.toolbar)
    Toolbar toolbar;
    @BindView(R.id.calendar_View)
    MNCalendarVertical calendarView;
    @Autowired
    int whether; //1 区间否 2 区间是  3都可以选 4 可选之前不可选之后
    SimpleDateFormat myFmt=new SimpleDateFormat("yyyy-MM-dd");
    @Override
    protected int getLayoutId() {
        return R.layout.activity_calendar;
    }

    public static void start(int whether) {
        ARouter.getInstance().build(ARouterPath.getCalendarActivity())
                .withInt("whether",whether)
                .navigation();
    }

    @Override
    public void doWork() {
        ARouter.getInstance().inject(this);
        Log.e("TAG","  "+whether);
        initRecylerView();
        initListener();

    }

    private void initListener() {
        back.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                finish();
            }
        });
    }

    private void initRecylerView() {
        /**
         *  自定义设置相关
         */
        MNCalendarVerticalConfig mnCalendarVerticalConfig = new MNCalendarVerticalConfig.Builder()
                .setMnCalendar_showWeek(true)                   //是否显示星期栏
                .setMnCalendar_showLunar(true)                  //是否显示阴历
                .setMnCalendar_colorWeek("#000201")             //星期栏的颜色
                .setMnCalendar_titleFormat("yyyy年MM月")           //每个月的标题样式
                .setMnCalendar_colorTitle("#FF0000")            //每个月标题的颜色
                .setMnCalendar_colorSolar("#616161")            //阳历的颜色
                .setMnCalendar_colorLunar("#575656")            //阴历的颜色
                .setMnCalendar_colorBeforeToday("#D8D8D8")      //今天之前的日期的颜色
                .setMnCalendar_colorRangeBg("#9930C553")        //区间中间的背景颜色
                .setMnCalendar_colorRangeText("#FFFFFF")        //区间文字的颜色
                .setMnCalendar_colorStartAndEndBg("#258C3E")    //开始结束的背景颜色
                .setMnCalendar_countMonth(400)                    //显示多少月(默认6个月)
                .setMnCalendar_whetherRange(whether)                //是否需要区间
                .build();
        calendarView.setConfig(mnCalendarVerticalConfig);
        /**
         * 区间选取完成监听
         */
        calendarView.setOnCalendarRangeChooseListener(new OnCalendarRangeChooseListener() {
            @Override
            public void onRangeDate(Date startDate, Date endDate) {
                if(whether==2){
                    EventBusBean eventBusBean=new EventBusBean();
                    eventBusBean.setEndtime(myFmt.format(endDate));
                    eventBusBean.setStarttime(myFmt.format(startDate));
                    eventBusBean.setType(whether);
                    EventBus.getDefault().post(eventBusBean); //普通事件发布
                    finish();
                }else if(whether==3){
                    EventBusBean eventBusBean=new EventBusBean();
                    eventBusBean.setStarttime(myFmt.format(startDate));
                    eventBusBean.setType(whether);
                    EventBus.getDefault().post(eventBusBean); //普通事件发布
                    finish();
                }else if(whether==4){
                    EventBusBean eventBusBean=new EventBusBean();
                    eventBusBean.setStarttime(myFmt.format(startDate));
                    eventBusBean.setType(whether);
                    EventBus.getDefault().post(eventBusBean); //普通事件发布
                    finish();
                }
            }

            @Override
            public void onChoiceData(Date choiceDate) {
                if(whether==1){
                    EventBusBean eventBusBean=new EventBusBean();
                    eventBusBean.setStarttime(myFmt.format(choiceDate));
                    eventBusBean.setType(whether);
                    EventBus.getDefault().post(eventBusBean); //普通事件发布
                    finish();
                }else if(whether==3){
                    EventBusBean eventBusBean=new EventBusBean();
                    eventBusBean.setStarttime(myFmt.format(choiceDate));
                    eventBusBean.setType(whether);
                    EventBus.getDefault().post(eventBusBean); //普通事件发布
                    finish();
                }else if(whether==4){
                    EventBusBean eventBusBean=new EventBusBean();
                    eventBusBean.setStarttime(myFmt.format(choiceDate));
                    eventBusBean.setType(whether);
                    EventBus.getDefault().post(eventBusBean); //普通事件发布
                    finish();
                }
//
            }
        });
//        recyclerView.setLayoutManager(new LinearLayoutManager(this));
//        recyclerView.addItemDecoration(new GroupItemDecoration<String, String>());
//        recyclerView.setAdapter(new CalendarAdapter(this));
//        recyclerView.notifyDataSetChanged();
    }


}